package com.qf.smsplatform.strategy.strategy.Impl;

import com.qf.smsplatform.common.constants.CacheConstants;
import com.qf.smsplatform.common.constants.StrategyConstants;
import com.qf.smsplatform.common.model.StandardSubmit;
import com.qf.smsplatform.strategy.client.CacheClient;
import com.qf.smsplatform.strategy.strategy.Strategy;
import com.qf.smsplatform.strategy.util.PushErrorMessageUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * projectName: smsplatform
 *
 * @author: MaTianWei
 * time: 2021/8/12 20:46
 * description:手机号黑名单校验
 */
@Service(value = "black")
@Slf4j
public class BlackStrategyImpl implements Strategy {
   @Autowired
   private CacheClient cacheClient;

    //TODO 黑名单校验    已完成
    @Override
    public boolean execute(StandardSubmit submit) {
        log.info("[策略模块-黑名单校验] =====开始执行=====");
        //获取用户的手机号 并且拼接BLACK:(key) 去redis中查找看值是否为1
        String mobile = submit.getDestMobile();
        String key = CacheConstants.CACHE_PREFIX_BLACK + mobile;
        //去redis里面找
        String value = cacheClient.get(key);
        //判断当前用户的手机号是否是黑名单
        //看看值是不是 1
        if("1".equals(value)){
        //值是1,说明他在黑名单里面,发送失败
            PushErrorMessageUtil.sendLog(submit, StrategyConstants.STRATEGY_ERROR_BLACK);
            PushErrorMessageUtil.sendReport(submit, StrategyConstants.STRATEGY_ERROR_BLACK);
            log.info("[策略模块-黑名单校验]  校验失败~~~~~~~~~~~~~~~~~~");
            return false;
        }
        log.info("[策略模块-黑名单校验] =====执行成功=====");
        return true;
    }
}
